package com.atguigu.paymentdemo.controller;

import com.atguigu.paymentdemo.entity.OrderInfo;
import com.atguigu.paymentdemo.enums.OrderStatus;
import com.atguigu.paymentdemo.service.OrderInfoService;
import com.atguigu.paymentdemo.service.WxPayService;
import com.atguigu.paymentdemo.vo.R;
import com.mysql.cj.log.Log;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

/**
 * @author longge
 * @Title:
 * @Description:
 * @date 2023/2/5 19:59
 */
@Api(tags = "订单管理")
@Slf4j
@RestController
@RequestMapping("/api/order-info")
public class OrderInfoController {

    @Autowired
    private OrderInfoService orderInfoService;

    @Autowired
    private WxPayService wxPayService;

    @ApiOperation("查询订单集合")
    @GetMapping("/list")
    public R list(){
        List<OrderInfo> list = orderInfoService.listOrderInfoByCreateTimeDesc();
        return R.ok().data("list",list);
    }

    /**
     * @Description: 查询本地订单状态
     * @param orderNo   订单号
     * @return
     */
    @ApiOperation("查询订单状态")
    @GetMapping("query-order-status/{orderNo}")
    public R queryOrderStatus(@PathVariable("orderNo") String orderNo){
        String orderStatus = orderInfoService.getOrderStatus(orderNo);
        if(OrderStatus.SUCCESS.getType().equals(orderStatus)){
            return R.ok().setMessage("支付成功");
        }
        return R.ok().setCode(101).setMessage("支付中...");
    }

}
